package com.code.thread.a1b2c3;

import java.util.concurrent.locks.LockSupport;

public class A1_Sync_Wait_Notify {

    private static final Object o = new Object();

    public static void main(String[] args) {

        char[] nums = "12345".toCharArray();
        char[] zimu = "ABCDE".toCharArray();

        new Thread(()->{
            synchronized (o){
                for (char c : nums) {
                    System.out.print(c);
                    o.notify();
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                o.notify();
            }

        }).start();

        new Thread(()->{
            synchronized (o){
                for (char c : zimu) {
                    System.out.print(c);
                    o.notify();
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                o.notify();
            }

        }).start();
    }
}
